#include "Netdefs.h"

#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

#include <cv.h>
#include <highgui.h>

#include "FrontCamHandler.h"
#include "mainDefs.h"

#include "OCREngine.h"

int main (int argc, char* argv[]) {
	string ip = argc > 1 ? argv[1] : "127.0.0.1";
	SocketClient *socketToDB = NULL;
	try {
		socketToDB = new SocketClient(ip, SERVERPORT); // this will have to be changed to command line args
	}
	catch (...) {
		cout << "Couldn't connect to " << ip << endl;
		exit(1);
	}

	/*
	cout << "Connected.." << endl;

	mysock->SendLine("FrontCam connected");
	string rcv(mysock->ReceiveLine());
	cout << "Recieved: " << rcv << endl;
	*/


#ifdef AVI_MODE
	CvCapture* camCapture = cvCaptureFromFile( TEST_AVI );

#endif
#ifdef CAMERA_MODE
	CvCapture* camCapture = cvCaptureFromCAM( CAMERA_DEVICE );
#endif

	// let's init the OCREngine:
	OCREngine::instance()->init("digits/");

	FrontCamHander FCH(camCapture,socketToDB);
	FCH.operate();

	delete socketToDB;
	return 0;
}